package com.example.smartcitymovie.dataRepo;

import com.example.smartcitymovie.bean.AreaThreaterBean;
import com.example.smartcitymovie.bean.LocalAddressBean;
import com.example.smartcitymovie.bean.MovieBannerBean;
import com.example.smartcitymovie.bean.MovieListBean;
import com.example.smartcitymovie.bean.MovieMessageBean;
import com.example.smartcitymovie.bean.PreviewMovieListBean;
import com.example.smartcitymovie.bean.TheaterTimesListBean;
import com.example.smartcitymovie.bean.TheatreMessageBean;
import com.example.smartcitymovie.bean.TodayWeatherBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class ApiData {

    private static final String[] imagesList = new String[]{
            "https://pic.netbian.com/uploads/allimg/240511/105348-171539602826dd.jpg",
            "https://pic.netbian.com/uploads/allimg/240510/170337-17153318178e74.jpg",
            "https://pic.netbian.com/uploads/allimg/240416/002020-17131980205383.jpg",
            "https://pic.netbian.com/uploads/allimg/240509/010156-1715187716333f.jpg",
            "https://pic.netbian.com/uploads/allimg/240410/223535-17127597352d7a.jpg",
            "https://pic.netbian.com/uploads/allimg/240509/001836-17151851161deb.jpg",
            "https://pic.netbian.com/uploads/allimg/240509/002119-17151852793df8.jpg",
            "https://pic.netbian.com/uploads/allimg/240509/005617-17151873778499.jpg"
    };
    private static AreaThreaterBean areaThreaterBean;

    private static MovieListBean movieListBean;

    private static TheaterTimesListBean theaterTimesListBean;

    public static AreaThreaterBean getAreaThreaterBean() {
        areaThreaterBean = new AreaThreaterBean();
        ArrayList<AreaThreaterBean.RowsBean> rowsBeans = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            rowsBeans.add(AreaThreaterBean.RowsBean.
                    builder()
                    .id(i)
                    .area("沙河口区")
                    .cover(getRandomImage())
                    .city("大连市")
                    .brand("brand")
                    .distance("100米")
                    .name("中影星美国际影城")
                    .address("大连高新技术产业园区软件园路1a-12号")
                    .score(93)
                    .movieId(1)
                    .build());
        }
        areaThreaterBean.setRows(rowsBeans);
        return areaThreaterBean;
    }


    /**
     * 获取电影轮播图数据
     *
     * @return
     */
    public static MovieBannerBean getMovieBannerBean() {
        MovieBannerBean movieBannerBean = new MovieBannerBean();
        ArrayList<MovieBannerBean.RowsBean> movieBannerBeans = new ArrayList<>();
        List<String> urlList = new ArrayList<String>() {{
            add("https://pic.netbian.com/uploads/allimg/240424/003411-1713890051411d.jpg");
            add("https://pic.netbian.com/uploads/allimg/240429/225620-1714402580ab97.jpg");
            add("https://pic.netbian.com/uploads/allimg/240425/163038-1714033838bbaa.jpg");
        }};
        for (int i = 0; i < urlList.size(); i++) {
            movieBannerBeans.add(MovieBannerBean.RowsBean.builder()
                    .advImg(urlList.get(i))
                    .advTitle("")
                    .appType("")
                    .sort(0)
                    .build());
        }
        movieBannerBean.setRows(movieBannerBeans);
        return movieBannerBean;
    }

    public static LocalAddressBean getLocalAddressBean() {
        LocalAddressBean localAddressBean = new LocalAddressBean();
        LocalAddressBean.DataBean dataBean = LocalAddressBean.DataBean.builder()
                .area("沙河口区")
                .location("五一广场")
                .city("大连市")
                .province("辽宁省")
                .build();
        localAddressBean.setData(dataBean);
        return localAddressBean;
    }

    public static MovieListBean getMovieListBean() {
        if (movieListBean != null) {
            return movieListBean;
        }
        movieListBean = new MovieListBean();
        ArrayList<MovieListBean.RowsBean> rowsBeans = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            rowsBeans.add(MovieListBean.RowsBean.builder()
                    .id(i)
                    .name("悬崖之上")
                    .category("3")
                    .cover(getRandomImage())
                    .playType("3")
                    .score(5)
                    .duration(120)
                    .playDate("2021-04-30")
                    .likeNum(143137)
                    .favoriteNum(198026)
                    .language("中文")
                    .introduction("<p>上世纪三十年代，四位曾在苏联接受特训的共产党 特</p>")
                    .other(null)
                    .recommend("Y")
                    .build());
        }
        movieListBean.setRows(rowsBeans);
        return movieListBean;
    }

    public static MovieMessageBean getMovieDetailDataById(Integer id) {
        if (movieListBean == null){
            getMovieListBean();
        }
        MovieListBean.RowsBean rowsBean = movieListBean.getRows().stream().filter(r -> r.getId() == id).findFirst().get();
        MovieMessageBean messageBean = new MovieMessageBean();
        MovieMessageBean.DataBean dataBean = MovieMessageBean.DataBean
                .builder()
                .id(rowsBean.getId())
                .name(rowsBean.getName())
                .category(rowsBean.getCategory())
                .cover(rowsBean.getCover())
                .playType(rowsBean.getPlayType())
                .score(rowsBean.getScore())
                .duration(rowsBean.getDuration())
                .playDate(rowsBean.getPlayDate())
                .likeNum(rowsBean.getLikeNum())

                .favoriteNum(rowsBean.getFavoriteNum())
                .language(rowsBean.getLanguage())
                .introduction(rowsBean.getIntroduction())
                .build();
        messageBean.setData(dataBean);
        return messageBean;
    }

    public static TodayWeatherBean getTodayWeatherBean() {
        TodayWeatherBean todayWeatherBean = new TodayWeatherBean();
        TodayWeatherBean.DataBean dataBean = TodayWeatherBean.DataBean.builder()
                .maxTemperature("12")
                .uv("弱")
                .minTemperature("24")
                .temperature("21")
                .weather("晴")
                .humidity("60")
                .air("60")
                .apparentTemperature("13")
                .label("今天")
                .day(1)
                .build();
        todayWeatherBean.setData(dataBean);
        return todayWeatherBean;
    }

    public static PreviewMovieListBean getPreviewMovieListBean() {
        PreviewMovieListBean previewMovieListBean = new PreviewMovieListBean();
        List<PreviewMovieListBean.RowsBean> rowsBeans = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            rowsBeans.add(PreviewMovieListBean.RowsBean.builder()
                    .id(i)
                    .name("悬崖之上")
                    .cover(getRandomImage())
                    .video("")
                    .playDate("2021-05-01")
                    .introduction("<p>上世纪三十年代，四位曾在苏联接受特训的共产党 特</p>")
                    .build());
        }
        previewMovieListBean.setRows(rowsBeans);
        return previewMovieListBean;
    }

    public static TheaterTimesListBean getTheaterTimesListBean() {
        if(theaterTimesListBean!=null){
            return theaterTimesListBean;
        }
        theaterTimesListBean = new TheaterTimesListBean();
        ArrayList<TheaterTimesListBean.RowsBean> rowsBeans = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            rowsBeans.add(TheaterTimesListBean.RowsBean
                    .builder()
                    .id(i)
                    .theaterId(i)
                    .roomId(i)
                    .startTime("10:30")
                    .endTime("11:45")
                    .price(36.0)
                    .playType("1")
                    .playDate("2021-05-09")
                    .saleNum(40)
                    .movieId(getRandomInt(10))
                    .totalNum(80)
                    .status("1")
                    .theatreName("北联影城")
                    .roomName("1号厅")
                    .movieName("悬崖之上")
                    .build());
        }
        theaterTimesListBean.setRows(rowsBeans);
        return theaterTimesListBean;
    }

    public static TheaterTimesListBean getTheaterTimesListBeanByMovieId(int movieId) {
        TheaterTimesListBean theaterTimesListBean1 = new TheaterTimesListBean();
        List<TheaterTimesListBean.RowsBean> rowsBeans = theaterTimesListBean.getRows().stream().filter(r -> r.getMovieId() == movieId).collect(Collectors.toList());
        theaterTimesListBean1.setRows(rowsBeans);
        return theaterTimesListBean1;
    }

    public static TheatreMessageBean getTheaterTimesListBeanNyThreadId(int threadId) {
        if (theaterTimesListBean==null){
            getTheaterTimesListBean();
        }
        TheatreMessageBean theatreMessageBean = new TheatreMessageBean();
        TheaterTimesListBean.RowsBean rowsBean = theaterTimesListBean.getRows().stream().filter(r -> r.getTheaterId() == threadId).findFirst().get();
        theatreMessageBean.setData(TheatreMessageBean.DataBean.builder()
                .id(rowsBean.getId())
                .name(rowsBean.getTheatreName())
                .cover(getRandomImage())
                .province("辽宁省")
                .city("大连市")
                .address("高新园区黄浦路500号万达广场4层")
                .area("甘井子区")
                .movieId(rowsBean.getMovieId())
                .score(63)
                .distance("300米")
                .build());

        return theatreMessageBean;
    }


    private static String getRandomImage() {
        Random random = new Random();
        return imagesList[random.nextInt(imagesList.length)];
    }

    private static Integer getRandomInt(int maxInt) {
        Random random = new Random();
        return random.nextInt(maxInt);
    }

}
